<?php
namespace app\api\controller;

use think\Controller;
use think\Db;
header("ACCESS-CONTROL-ALLOW-ORIGIN:http://114.215.68.205");
class Version extends Controller
{
	public function versionUpdate(){
		$apktype = input('apktype');
		$systype = input('systype');
		$row = array(
				'result'=>0,
				'ResultMsg'=>'不存在',
		);
		if( !empty($apktype) && !empty($systype)){
			$apk = Db::name('version')->field('id,version,version_url,desc,upgrade')->where(['type'=>$apktype,'systemtype'=>$systype])->order("number DESC")->find();
			if($apk['id']){
				if( 1==intval($systype) ){
					$url = $_SERVER['HTTP_HOST'].'/apk/'.$apk['version_url'];
				}else{
//					$url = 'itms-services://?action=download-manifest&url='.$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/ios/'.$apk['version_url'];
					$url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/api/version/version';
				}
				$row = array(
						'result'=>1,
						'ResultMsg'=>'',
						'datas'=>array(
								'upgrade'=>$apk['upgrade'],
								'number'=>$apk['version'],
								'apk_url'=> $url,
								'desc' => html_entity_decode($apk['desc'])
						)
				);
			}
		}
		echo json_encode($row,JSON_UNESCAPED_UNICODE);
	}
	public function version(){
		$detail = Db::name('version')->where(['type'=>2,'systemtype'=>2])->order("number desc")->find();
		$detail['url'] =  'itms-services://?action=download-manifest&url='.$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/ios/'.$detail['version_url'];
		$detail['desc'] = str_replace("\n","<br>",html_entity_decode($detail['desc']));
		$this->assign('detail',$detail);
		return $this->fetch();
	}
}